/*
 * Canvas Game Engine - FPS Counter
 *
 * version: 0.1
 *
 * author: Fabio Rotondo <fabio@rotondo.it>
 *
 */

function CGEFPSCounter ( fps )
{
	var d = ( new Date () ).getTime ();

	this.fps = fps;

	this.last_time = 0;

	this.last_frame_count = 0;
	this.frame_last = d;
	this.counter = 0;
	this.last_time = d;
	this.step = 1;

	this.debug = false;
}

CGEFPSCounter.prototype.count = function ()
{
	var d = ( new Date () ).getTime ();
	var delta = d - this.last_time;

	this.step = ( delta / 1000 ) * this.fps;
	this.last_time = d;
	this.counter ++;

	if ( d >= this.frame_last + 1000 )
	{
		if ( this.debug ) console.log ( "frame event: %s - ctr: %s", this.step, this.counter );
		this.last_frame_count = this.counter;
		this.counter = 0;
		this.frame_last = d;
	}
};
